package com.concerneyes.glasses;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.Ssiwo.sdk.SsiwoFacenginActivity;
import com.concerneyes.MainActivity;
import com.concerneyes.R;
import com.concerneyes.trytoglasses.TryToGlassesView;

import java.util.ArrayList;

import common.AbsActivity;
import util.ActivityUtil;

/**
 * Created by Administrator on 2017/7/4 0004.
 */

public class TryItActivity extends SsiwoFacenginActivity implements View.OnClickListener {

    private LinearLayout wearview_parent;
    private ImageView wear_glasses;
    private ImageView change_camera;
    //判断是否第一次进入
    private boolean isFrist = true;
    private View wearView;
    private ArrayList<String> skus;
    private int a = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_try_it);
        //初始化布局
        initView();
    }

    private void initView() {
        //试戴View的父布局
        wearview_parent = (LinearLayout) findViewById(R.id.WearViewParent);
        //得到试戴View
        wearView = getWearView();

        mUnityPlayer = TryToGlassesView.wearEngin;

        //将试戴View添加进父布局（只有将试戴View添加进去，试戴页面才会显示，可根据具体需求选择添加时机）
        wearview_parent.addView(wearView);
        mUnityPlayer.resume();
        //试戴按钮
        wear_glasses = (ImageView) findViewById(R.id.bt_wear_glasses);
        //切换相机按钮
        change_camera = (ImageView) findViewById(R.id.bt_change_camera);
        wear_glasses.setOnClickListener(this);
        change_camera.setOnClickListener(this);

        //测试眼镜sku集合
        skus = new ArrayList<>();
        skus.add("SW_SFC_2101_54_c65_61_61_61_65");
        skus.add("SW_SFC_2102_50_c70_89_70_89_70");
        skus.add("SW_SFC_2102_52_c84_84_84_84_84");
        skus.add("SW_SFC_2104_52_c64_64_64_64_64");
        skus.add("SW_SFC_2109_52_c61_61_61_61_61");
        skus.add("SW_SFC_2123_50_c50_50_50_50_50");
        skus.add("SW_SFC_2125_50_c65_65_65_65_65");
        skus.add("SW_SFC_2126_50_c60_50_50_50_60");
        skus.add("SW_SFC_2127_54_c60_60_60_60_60");
        skus.add("SW_SFC_2130_52_c60_67_67_67_60");
        skus.add("SW_SFC_2500_54_c64_33_33_33_64");
        skus.add("SW_SFC_2503_48_c89_53_53_53_89");
    }

    @Override
    protected void onPause() {
        wearview_parent.removeView(wearView);
        super.onPause();
    }

    @Override
    protected void onResume() {
        if (isFrist) {
            mUnityPlayer.resume();
            isFrist = false;
        } else {
            wearview_parent.addView(wearView);
        }

        super.onResume();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //试戴按钮点击事件
            case R.id.bt_wear_glasses:
                Log.e(this.getClass().getSimpleName(), "onClick==>1231213");
                String glassesInfo = skus.get(a);
                a++;
                if (a >= skus.size() - 1) {
                    a = 0;
                }
                /**
                 * 请填写本公司提供的appId,
                 * appId在appId.txt里面
                 */
                String appId = "8AAfkhUKpU0sjeQrDtC6SrhRKNqA6hGb";
                //进行app身份校验
                checkAppID(appId);
                //试戴指定sku的眼镜,点击可切换
                wearGlasses(glassesInfo);
                break;
            //切换摄像头按钮点击事件
            case R.id.bt_change_camera:
                //切换摄像头
                changeCamera();
                break;
        }
    }
}
